﻿using System.Collections;
using System.Collections.Generic;

namespace Flowertwig.Utils.Entities
{
    public class KeyValueEnumerator<TKey, TValue> : IEnumerator<SerializableKeyValuePair<TKey, TValue>>
    {
        readonly IEnumerator<KeyValuePair<TKey, TValue>> _enumerator;

        public KeyValueEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> enumerator)
        {
            _enumerator = enumerator;
        }

        #region IEnumerator<KeyValuePair<TKey,TValue>> Members
        public SerializableKeyValuePair<TKey, TValue> Current
        {
            get
            {
                KeyValuePair<TKey, TValue> value = _enumerator.Current;
                return new SerializableKeyValuePair<TKey, TValue>(value.Key, value.Value);
            }
        }
        #endregion

        #region IDisposable Members
        public void Dispose()
        {
            if (_enumerator != null)
                _enumerator.Dispose();
        }
        #endregion

        #region IEnumerator Members
        object IEnumerator.Current
        {
            get { return Current; }
        }

        public bool MoveNext()
        {
            return _enumerator != null && _enumerator.MoveNext();
        }

        public void Reset()
        {
            if (_enumerator != null)
                _enumerator.Reset();
        }
        #endregion
    }
}
